package com.lonty.intelligence.service;

import com.lonty.intelligence.mapper.SpotMapper;
import com.lonty.intelligence.model.Spot;
import com.lonty.intelligence.util.UUIDUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 陈璇
 * @Date 2020/7/9 11:10
 * @Version 1.0
 */
@Service
public class SpotService {

    @Resource
    private SpotMapper spotMapper;

    /**
     * 保存点击
     * @param name
     * @return
     */
    public boolean saveSpot(String name){
        Spot spot = new Spot();
        spot.setId(UUIDUtil.randomID());
        spot.setName(name);
        spot.setNum(0);
        return spotMapper.saveSpot(spot) > 0;
    }

    /**
     * 获取点击
     * @return
     */
    public List<Spot> getSpotList(){
        return spotMapper.getSpotList();
    }

    /**
     * 修改点击数
     * @param id
     * @return
     */
    public boolean modifyNum(String id){
        Spot spot = spotMapper.getById(id);
        return spotMapper.modifyNum(id, spot.getNum() + 1) > 0;
    }

}
